package com.yanqu.road.logic.activity.foxcard.game.sorcery;

import com.alibaba.fastjson.JSONObject;
import com.yanqu.road.logic.activity.foxcard.game.FoxCardGameLogic;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 升级最等级最高的牌型{0}次
 */
public class FoxCardSorceryUse7 extends FoxCardSorceryUseBase{
    @Override
    protected boolean sorceryUse(FoxCardGameLogic gameLogic) {
        int num = sorceryConfig.getParamList().get(0);

        List<JSONObject> comboSortList = new ArrayList<>();
        for (Map.Entry<Integer, List<Integer>> entry : gameLogic.getGameData().getComboInfoMap().entrySet()) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("comboId", entry.getKey());
            jsonObject.put("level", entry.getValue().get(0));
            jsonObject.put("showNum", entry.getValue().get(1));
            comboSortList.add(jsonObject);
        }
        comboSortList.sort((o1, o2) -> {
            int level1 = o1.getIntValue("level");
            int level2 = o2.getIntValue("level");
            int compare = Integer.compare(level2, level1);
            if (compare == 0) {
                int comboId1 = o1.getIntValue("comboId");
                int comboId2 = o2.getIntValue("comboId");
                compare = Integer.compare(comboId1, comboId2);
            }
            return compare;
        });

        JSONObject result = comboSortList.get(0);
        int comboId = result.getIntValue("comboId");
        gameLogic.comboLevelUp(comboId, num);

        return true;
    }
}
